<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
  <base href="<%=basePath %>">
  <meta charset="utf-8">
  <title>添加分类</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="js/layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  <legend>添加项目分类</legend>
</fieldset><br><br>

<form class="layui-form"  id = "form1" >
  <div class="layui-form-item">
    <label class="layui-form-label">分类名称</label>
    <div class="layui-input-block">
      <input type="text" style="width:200px; " name="name" lay-verify="title" autocomplete="off" placeholder="请输入分类名称" class="layui-input"/>
    </div>
  </div>
  <br>
    <input type="hidden" name ="id" value="<%=request.getParameter("id")%>"/>
  </div>
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">分类描述</label>
    <div class="layui-input-block">
      <textarea placeholder="请输入分类描述" style="width:300px;"  class="layui-textarea" name="brief"></textarea>
    </div>
    <br>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>

    </div>
  </div>
</form>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;"/>

</body>
<script src="js/layui/layui.js" charset="utf-8"></script>
<script>
  layui.use(['form', 'layedit', 'laydate'], function() {
    var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;

    //监听提交
    form.on('submit(demo1)', function(data){
        $.post(
                url= "Ategory/addAtegory",
                data=$('#form1').serialize(),
                success=function (data) {
                  console.log(data);
                  if(data.statusCode==200){
                    parent.location.reload();
                    parent.layer.closeAll();
                  }if(data.statusCode==300){
                    layer.alert("该分类已存在",function () {
                      location.reload();
                    });
                  }
                }
        )
      return false;
    })
  })
</script>
</html>